package dao.hibernate;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import dao.*;

import model.*;

public class HibernateNewsDao extends GenericHibernateDAO<News, Long> implements NewsDao{
	
	@SuppressWarnings("unchecked")
	public List<News> getByParam(final String param) {
        return (List<News>) getHibernateTemplate().execute(new HibernateCallback() {
            public List<News> doInHibernate(Session session) throws HibernateException, SQLException {

				StringBuffer hql = new StringBuffer();
				hql.append("from News ");
				if(param.trim().length()>0){
					hql.append(" where "+param+"");
				}
				
				Query query =  session.createQuery(hql.toString());
				return query.list();
            }
        });
    }
}
